import os
import logging
import sys

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import users

class LoginPage(webapp.RequestHandler):
	def get(self):
		user = users.GetCurrentUser()
		if user:
			# User is already logged in. Redirect to home page of the user
			self.redirect("home")
		else:
			# Display the login link. On clicking the link and logging in, that page should redirect back to this page
			# and thus should get redirected to the user's home page

			self.response.headers['Content-Type'] = "text/html"
			self.response.out.write('''
				<html>
					<head> <title> DVD Share </title> </head>
					<body>
						<h1> Click <a href="%s">here</a> to login to DVD Share using your google account </h1>
					</body>
				</html>
				''' % (users.create_login_url(self.request.path)))
						
	
application = webapp.WSGIApplication([('/kumar/', LoginPage)], debug=True)
				 
def main():
	# main entry point

	util.run_wsgi_app(application);	
	

if __name__ == "__main__":
	main()
	
